package com.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.PageBean;
import com.bean.ShopingCar;
import com.serve.ShopService;
import com.serveImple.ShopServiceImpl;

/**
 * Servlet implementation class ShopCarServlet
 */
@WebServlet("/ShopCarServlet")
public class ShopCarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShopCarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		int defaultPage=1;		
		//处理从页面分页请求的当前页		
		PageBean pb=new PageBean();
 
		if(request.getAttribute("gid")!=null){
			int g_id= (int) request.getAttribute("gid");
			pb.setG_id(g_id);	
		}	
		pb.setCurrentPage(defaultPage); //默认获取第一页的数据		
	/*	Goods goods=(Goods) request.getAttribute("goods");*/
		/*if(goods!=null){
		int i=goods.getG_id();
		pb.setG_id(i);
		}		
		*/
		String str =request.getParameter("currentPage");
		if(str!=null){
			int number=Integer.parseInt(str);
			pb.setCurrentPage(number);
		}
		ShopService shopservice=new ShopServiceImpl();
		List<ShopingCar> shoplist=shopservice.show(pb);
		System.out.println(shoplist);
		request.setAttribute("pb",pb);
		/*request.setAttribute("shop", shoplist);*/
		request.setAttribute("shoplist", shoplist);
		//转发
		request.getRequestDispatcher("easybuy/shopcar.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
